<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="用户名" prop="roleName">
        <el-input v-model="queryParams.account" placeholder="请输入用户名" clearable style="width: 200px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
          @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-table v-loading="loading" :data="keyList">
          <el-table-column type="selection" width="100%" align="center" />
          <el-table-column label="编号" align="center" key="id" prop="id" />
          <el-table-column label="用户账户" align="center" key="account" prop="account" />
          <el-table-column label="机器码" align="center" key="machineCode" prop="machineCode" />
          <el-table-column label="解绑次数" align="center" key="unbindingNumber"
            prop="unbindingNumber" />
          <el-table-column label="到期时间" align="center" key="endTime" prop="endTime" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-close"
                @click="handleUpdate(scope.row)">解绑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { getAccountList, shutDown } from "@/api/system/account";
export default {
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 遮罩层
      loading: false,
      // 卡密列表
      keyList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isActivated: undefined,
      },
      // 回显卡密
      keyList: "",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取卡密列表
    getList() {
      this.loading = true;
      getAccountList(this.queryParams).then((response) => {
        this.keyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 解绑用户
    handleUpdate(scope) {
      shutDown(scope.account).then((response) => {
        this.$modal.msgSuccess(response.msg);
        this.getList();
      });
    },

    // 搜索
    handleQuery() {
      this.loading = true;
      getAccountList(this.queryParams).then((response) => {
        this.keyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    resetQuery() {},
  },
};
</script>